package iss.java;

import iss.java.list.MyList;
import iss.java.list.Node;

import java.util.List;

public class Main_B {
    public static void main(String[] args) throws InterruptedException{


        MyList list = new MyList();

        Node node = list.getHead();
        


        InsertThread i1 = new InsertThread(list, node, 10);
        InsertThread i2 = new InsertThread(list, node, 11);
        InsertThread i3 = new InsertThread(list, node, 12);
        InsertThread i4 = new InsertThread(list, node, 13);

        Thread it1 = new Thread(i1);
        Thread it2 = new Thread(i2);
        Thread it3 = new Thread(i3);
        Thread it4 = new Thread(i4);

        it1.start();
        it2.start();
        it3.start();
        it4.start();

        Thread.sleep(2000);
        list.forwardPrint();
        list.backwardPrint();

        Node node3 = list.getHead().getNext();
        Node node2 = list.getHead().getNext().getNext();
        RemoveThread r2 = new RemoveThread(list, node2);
        RemoveThread r3 = new RemoveThread(list, node3);
        Thread rt2 = new Thread(r2);
        Thread rt3 = new Thread(r3);
        rt2.start();
        rt3.start();

        Thread.sleep(2000);
        list.forwardPrint();
        list.backwardPrint();
    }
}

class InsertThread implements Runnable {
    private int num;
    private Node node;
    private MyList list;

    InsertThread(MyList list, Node node, int num) {
        this.num = num;
        this.node = node;
        this.list = list;
    }

    public void run() {
        list.insert(node, num);
    }
}

class RemoveThread implements Runnable {
    private Node node;
    private MyList list;

    RemoveThread(MyList list, Node node) {
        this.node = node;
        this.list = list;
    }

    public void run() {
        list.remove(node);
    }
}